------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_799
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/prepare/collapse_org.log
  log type:  text
 opened on:  27 Nov 2024, 17:33:08

. ********************************************************************************
. 
. * collapse_org.do
. * Collapses 1987-2017 march cps data by cohort and other 
. * Extracts made:
. *       1) year-cohort level
. *       2) year-cohort-state (current state)
. *       3) year-cohort-attainment
. *       4) year-cohort-attainment-state
. 
. * Edited, RY, 3/7/2018 
. * modified JR 4/30/2018: Use 2, 4, and 5 education groups.
. *                        Remove merge to unemployment rate (now in combinecollapse)
. * modified JR 1/9/2019:  Reduce variables to keep, and generate new weight that is limited
. *                        to those with non-missing earnings.
. 
. cap project, doinfo

. if _rc==0 {
.          local pdir "`r(pdir)'"                                                     // the project's main dir.
.          local dofile "`r(dofile)'"                                                 // do-file's stub name
.    local sig {bind:{hi:[`dofile'.dta. RP : `dofile'.do, `c(current_date)']}}    // a signature in notes
.    local doasproject=1
. }

. else {
.    local pdir "~/GRscarring"
.    local dofile "collapse_org"
.    local doasproject=0
. }

. 
. set more off

. local rootdir "`pdir'"

. local thisdir "`pdir'"

. 
. 
. local prepdata "`pdir'/scratch"

. local rawdata "`pdir'/rawdata"

. 
. 
. ***************************************************************************************************************
. *************************************
. ********** 0: LOAD DATA *************
. *************************************
. 
. *** ORG DATA ***
. 
. if `doasproject'==1 {
.   project, uses("`prepdata'/extractorg_morg.dta.gz")
project GRscar_erratum > do-file uses: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/extractorg_morg.dta.gz" filesig(8195742
> 91:643171877)
. }

. 
. !zcat `prepdata'/extractorg_morg.dta.gz > `prepdata'/extractorg_morg.dta


. use `prepdata'/extractorg_morg.dta, clear

. !rm `prepdata'/extractorg_morg.dta


. 
. *use if inlist(stfips, 1, 3, 7) & inlist(educ5,2,3) using  `prepdata'/extractorg.dta, clear
. 
. 
. *** COHORT: ****
. gen cohort=(year-age)

. 
. 
. ************************************************
. *********** 1: SAMPLE RESTRICTIONS *************
. ************************************************
. 
. keep if age>15 & age<81
(315,480 observations deleted)

. 
. 
. ************************************************
. *********** 2: MAKE SOME VARIABLES *************
. ************************************************
. 
. *** Variables to collapse by:
. 
. * educ5
. gen educ4=.
(12,854,398 missing values generated)

. replace educ4=1 if inlist(educ92,0,1,2,3,4,5,6,7,8)==1
(2,598,711 real changes made)

. replace educ4=2 if inlist(educ92,9)==1
(4,292,854 real changes made)

. replace educ4=3 if inlist(educ92,10,11,12)==1
(3,049,076 real changes made)

. replace educ4=4 if inlist(educ92,13,14,15,16)==1
(2,913,756 real changes made)

.   
. gen educ5=educ4
(1 missing value generated)

. replace educ5=5 if inlist(educ92,14,15,16)
(1,042,950 real changes made)

. drop if educ5==.
(1 observation deleted)

. label define attain_l 1 "LTHS" 2 "HS" 3 "Some col." 4 "BA" 5 "MA+"

. label values educ5 attain_l

. gen byte educ2=(inlist(educ5, 4, 5)) if educ5<.

. 
. gen orgwgt_rw_l=orgwgt if rw_l<.
(5,831,780 missing values generated)

. gen earnwt_rw_l=earnwt if rw_l<.
(5,831,780 missing values generated)

. 
. rename gestfips fipsst

. 
. ******** Sex ******
. replace sex = 0 if sex == 2
(6,726,990 real changes made)

. tab sex

        Sex |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |  6,726,990       52.33       52.33
       Male |  6,127,407       47.67      100.00
------------+-----------------------------------
      Total | 12,854,397      100.00

. 
. sort year cohort fipsst educ5

. 
. tempfile all 

. save `all'
file /tmp/St2868349.000004 saved as .dta format

. 
. *************************************
. *********** 3: COLLAPSE *************
. *************************************
. /*Paid hourly (paidhre)
> Wage (NBER def) (w_nber)
> Wage (no topcode/OT adjustment) (w_no_no)
> Hours used for wage calculations (hours_jr)
> Wage (JR definition) (wage_jr)
> Real wage (JR definition) (rw)
> Real wage (CEPR method) (rw_cep)
> Real wage (NBER definition) (rw_nber)
> Occupation mean earnings (wage_occup) */
. 
. *local vlist "rw rw_l rw_nber rw_nber_l rwage_occup usualhoursi"
. local vlist "rw_l"

. local wlist "orgwgt orgwgt_rw_l earnwt earnwt_rw_l"

. 
. ** 1.1: Year-cohort
. collapse (mean) `vlist' sex ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort)

. 
. 
. tempfile yc

. save `yc'
file /tmp/St2868349.000005 saved as .dta format

. 
. ** 1.2: Year-cohort-state
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort fipsst)

. 
. tempfile ycs

. save `ycs'
file /tmp/St2868349.000006 saved as .dta format

. 
. ** 1.3: Year-cohort-attainment (5 category)
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort educ5)

. 
. tempfile yca5

. save `yca5'
file /tmp/St2868349.000007 saved as .dta format

. 
. ** 1.4: Year-cohort-attainment (5 category)-state
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort fipsst educ5)

. tempfile yca5s

. save `yca5s'
file /tmp/St2868349.000008 saved as .dta format

. 
. ** 1.5: Year-cohort-attainment (4 category)
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort educ4)

. tempfile yca4

. save `yca4'
file /tmp/St2868349.000009 saved as .dta format

. 
. ** 1.6: Year-cohort-attainment (4 category)-state
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort fipsst educ4)

. tempfile yca4s

. save `yca4s'
file /tmp/St2868349.00000a saved as .dta format

. 
. ** 1.7: Year-cohort-attainment (2 category)
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort educ2)

. 
. tempfile yca2

. save `yca2'
file /tmp/St2868349.00000b saved as .dta format

. 
. ** 1.8: Year-cohort-attainment (2 category)-state
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort fipsst educ2)

. tempfile yca2s

. save `yca2s'
file /tmp/St2868349.00000c saved as .dta format

. 
. ** 1.9: Year-cohort-attainment (2 category)-sex-state
. use `all', clear

. collapse (mean) `vlist' ///
>         (count) n_obs=orgwgt (rawsum) `wlist',  ///
>         by(year cohort fipsst educ2 sex)

. tempfile yca2ss

. save `yca2ss'
file /tmp/St2868349.00000d saved as .dta format

. 
.   
. ********************************************
. **** 5.  LABEL VARIABLES *****
. ********************************************
.   foreach set in yc ycs yca5 yca5s yca4 yca4s yca2 yca2s yca2ss {
  2.     use ``set''
  3.     label var n_obs "Number of observations in cell"
  4.     label var orgwgt "Sum of ORG weights (unweighted/raw)"      
  5.     label var rw_l "Log of real wage (JR/CEPR definition)"
  6.     label var orgwgt_rw_l "Sum of ORG weights (non-missing rw_l)"       
  7.     label var earnwt "Sum of ORG earnings weights (unweighted/raw)"     
  8.     label var earnwt_rw_l "Sum of ORG earnings weights (non-missing rw_l)"      
  9. 
.     save ``set'', replace
 10. }
file /tmp/St2868349.000005 saved as .dta format
file /tmp/St2868349.000006 saved as .dta format
file /tmp/St2868349.000007 saved as .dta format
file /tmp/St2868349.000008 saved as .dta format
file /tmp/St2868349.000009 saved as .dta format
file /tmp/St2868349.00000a saved as .dta format
file /tmp/St2868349.00000b saved as .dta format
file /tmp/St2868349.00000c saved as .dta format
file /tmp/St2868349.00000d saved as .dta format

. 
. drop orgwgt orgwgt_rw_l

. rename earnwt orgwgt

. rename earnwt_rw_l orgwgt_rw_l

. 
. *************************************
. ****** 6: COMPRESS AND SAVE *********
. *************************************
. 
. foreach col in yc ycs yca5 yca5s yca4 yca4s yca2 yca2s yca2ss {
  2.         use ``col'', clear
  3.         save "`prepdata'/collapse_org_`col'.dta", replace
  4.         *! gzip -f `prepdata'/`dofile'_`col'.dta
.         *project, creates("`prepdata'/`dofile'_`col'.dta.gz")
.         if `doasproject'==1 project, creates("`prepdata'/collapse_org_`col'.dta")
  5. }
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yc.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yc.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yc.dta" filesig(1396328
> 040:173008)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_ycs.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_ycs.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_ycs.dta" filesig(369975
> 3190:7483670)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca5.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca5.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca5.dta" filesig(59209
> 0257:825902)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca5s.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca5s.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca5s.dta" filesig(3662
> 349351:40435801)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca4.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca4.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca4.dta" filesig(21494
> 84213:666156)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca4s.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca4s.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca4s.dta" filesig(6653
> 70958:33286908)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca2.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca2.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca2.dta" filesig(30430
> 04835:298673)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca2s.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca2s.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca2s.dta" filesig(2963
> 185735:14662449)
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca2ss.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/collapse_org_yca2ss.dta saved
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/collapse_org_yca2ss.dta" filesig(233
> 1741259:29361206)

. 
. 
. * end of do file *
. 
. 
. 
end of do-file
      name:  plog_799
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/prepare/collapse_org.log
  log type:  text
 closed on:  27 Nov 2024, 17:35:27
------------------------------------------------------------------------------------------------------------------------------------
